import { PlayerDialog } from "./PlayerDialog";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Language } from "../../../../../extend/language/Language";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GBox } from "../../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TaskProcessPanel } from "../../task/imgtxt/TaskProcessPanel";
import { RewardList2 } from "./RewardList2";
import { RefreshPanel } from "./RefreshPanel";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { EffectManager } from "../../../manager/EffectManager";
import { CycleInfo } from "../../../model/CycleInfo";
import { ColorConfig } from "../../../resource/ColorConfig";
import { ETaskStatus } from "../../../../../Message/Game/ETaskStatus";
import { GuideTipsManager } from "../../../manager/GuideTipsManager";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Cache } from "../../../cache/Cache";
import { LineBox } from "../../guide/LineBox";
type int = number;
//class CycleList
    
    export  class CycleList extends PlayerDialog
    {
        constructor()
        {
            super();
            this._tf = new GTextFormat(FontUtil.songtiName, 12, 16580298, true, null, null, null, null, flash.text.TextFormatAlign.LEFT);
            this._line = GlobalClass.getBitmap("Line");
            this._line.width = 400;
            this._line.x = -40;
            addChild(this._line);
            this._titleTxt = new Object /* flash.text.TextField */();
            this._titleTxt.y = 20;
            this._titleTxt.width = 70;
            this._titleTxt.defaultTextFormat = new GTextFormat(FontUtil.songtiName, 12, 16777215, true, null, null, null, null, flash.text.TextFormatAlign.LEFT);
            this._titleTxt.text = Language.getString(20237) + "：";
            this._titleTxt.filters = [FilterConst.nameGlowFilter];
            this._titleTxt.selectable = false;
            addChild(this._titleTxt);
            this._colorPanel = new GBox();
            this._colorPanel.direction = GBoxDirection.HORIZONTAL;
            this._colorPanel.x = this._titleTxt.x + this._titleTxt.width + 5;
            this._colorPanel.y = this._titleTxt.y - 2;
            this._colorPanel.mouseChildren = false;
            this._colorPanel.mouseEnabled = false;
            addChild(this._colorPanel);
            this._moveAward = new Object /* flash.text.TextField */();
            this._moveAward.htmlText = HTMLUtil.addColor("<u><a href=\'event: moveAward\'>" + Language.getString(20511) + "</a></u>", "#f9ff5d");
            this._moveAward.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._moveAward.filters = [FilterConst.nameGlowFilter];
            this._moveAward.selectable = false;
            this._moveAward.width = 80;
            this._moveAward.x = 185;
            this._moveAward.y = this._titleTxt.y - 2;
            addChild(this._moveAward);
            this._cycleTxt = ObjCreate.createTextField("", 0, 0, -1, -1, null, GlobalStyle.getTextFormatDefaultFont(GlobalStyle.textFormat1));
            this._cycleTxt.x = 10;
            this._cycleTxt.y = 41;
            this._cycleTxt.width = 270;
            this._cycleTxt.filters = [FilterConst.nameGlowFilter];
            this._cycleTxt.selectable = false;
            addChild(this._cycleTxt);
            this._taskProcess = new TaskProcessPanel();
            addChild(this._taskProcess);
            this._countTxt = new Object /* flash.text.TextField */();
            this._countTxt.defaultTextFormat = this._tf;
            this._countTxt.text = Language.getString(20512) + "：";
            this._countTxt.width = 70;
            this._countTxt.selectable = false;
            this._countTxt.filters = [FilterConst.nameGlowFilter];
            this._countTxt.x = 0;
            this._countTxt.y = 62;
            addChild(this._countTxt);
            this._countValue = new Object /* flash.text.TextField */();
            this._countValue.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._countValue.width = 200;
            this._countValue.textColor = 11661311;
            this._countValue.selectable = false;
            this._countValue.filters = [FilterConst.nameGlowFilter];
            this._countValue.y = this._countTxt.y - 2;
            this._countValue.x = this._countTxt.x + this._countTxt.width + 5;
            addChild(this._countValue);
            this._rewardTxt = new Object /* flash.text.TextField */();
            this._rewardTxt.defaultTextFormat = this._tf;
            this._rewardTxt.text = Language.getString(20094) + "：";
            this._rewardTxt.width = 68;
            this._rewardTxt.selectable = false;
            this._rewardTxt.filters = [FilterConst.nameGlowFilter];
            this._rewardTxt.x = 0;
            this._rewardTxt.y = this._countTxt.y + this._countTxt.textHeight + 8;
            addChild(this._rewardTxt);
            this._rewardList = new RewardList2();
            this._rewardList.x = this._rewardTxt.x + this._rewardTxt.width + 5;
            this._rewardList.y = this._rewardTxt.y - 2;
            addChild(this._rewardList);
            this._freeCount = new Object /* flash.text.TextField */();
            this._freeCount.defaultTextFormat = this._tf;
            this._freeCount.text = Language.getString(20513) + "：";
            this._freeCount.filters = [FilterConst.nameGlowFilter];
            this._freeCount.selectable = false;
            this._freeCount.width = 70;
            this._freeCount.x = 175;
            this._freeCount.y = this._countTxt.y;
            addChild(this._freeCount);
            this._freeTxt = new Object /* flash.text.TextField */();
            this._freeTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._freeTxt.width = 200;
            this._freeTxt.textColor = 11661311;
            this._freeTxt.selectable = false;
            this._freeTxt.filters = [FilterConst.nameGlowFilter];
            this._freeTxt.x = this._freeCount.x + this._freeCount.width;
            this._freeTxt.y = this._freeCount.y - 2;
            addChild(this._freeTxt);
            this._freeTimer = new Object /* flash.text.TextField */();
            this._freeTimer.defaultTextFormat = this._tf;
            this._freeTimer.filters = [FilterConst.nameGlowFilter];
            this._freeTimer.selectable = false;
            this._freeTimer.textColor = 16141388;
            this._freeTimer.width = 150;
            this._freeTimer.x = 160;
            this._freeTimer.y = this._freeCount.y + 20;
            this._freeTimer.text = Language.getString(20183) + "：00: 00: 00";
            addChild(this._freeTimer);
            this._refreshPanel = new RefreshPanel();
            this._refreshPanel.x = 0;
            this._refreshPanel.y = 145;
            this._refreshPanel.addEventListener(RefreshPanel.AutoBuySelectedChange, this.onAutoBuySelectedChange);
            addChild(this._refreshPanel);
            this._optBtn = new GButton();
            this._optBtn.styleName = "Button";
            this._optBtn.label = Language.getString(20514);
            this._optBtn.getChildAt(0).filters = [FilterConst.nameGlowFilter];
            this._optBtn.x = 212;
            this._optBtn.y = this._refreshPanel.y;
            this._optBtn.setSize(75, 22);
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onRefreshBtnClick);
            addChild(this._optBtn);
            return;
        }

        public /* override */ dispose(): void
        {
            this._optBtn.label = Language.getString(20514);
            EffectManager.glowFilterUnReg(this._optBtn);
            this.clearStar();
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
            }
            this._taskProcess.dispose();
            this._rewardList.dispose();
            this._cycleTxt.text = "";
            return;
        }

        public /* override */ get height(): number
        {
            return this._titleTxt.textHeight + this._cycleTxt.textHeight + 10;
        }

        public updateColor(arg1: CycleInfo): void
        {
            var loc2=null;
            this._info = arg1;
            this.clearStar();
            var loc1=1;
            while (loc1 <= arg1.color) 
            {
                loc2 = GlobalClass.getBitmap("star_" + arg1.color);
                this._colorPanel.addChild(loc2);
                ++loc1;
            }
            this._colorPanel.invalidate();
            this._rewardList.updateData(arg1.taskInfo.sTask.rewards);
            this._titleTxt.textColor = ColorConfig.instance.getCycleColor(arg1.color).intColor;
            this._freeTxt.text = arg1.freeCount + " / " + arg1.maxFreeCount + " " + Language.getString(20259);
            this.updateCountDown(this._info.totalSeconds);
            this.updateOptBtn(this._info);
            return;
        }

        public updateStatus(arg1: CycleInfo): void
        {
            this._info = arg1;
            var loc1=arg1.status;
            switch (loc1) 
            {
                case ETaskStatus._ETaskStatusCanGet:
                {
                    this._optBtn.enabled = true;
                    break;
                }
                case ETaskStatus._ETaskStatusNotCompleted:
                {
                    this._optBtn.enabled = true;
                    break;
                }
                case ETaskStatus._ETaskStatusHadCompleted:
                {
                    this._optBtn.enabled = false;
                    break;
                }
            }
            this._cycleTxt.htmlText = HTMLUtil.addColor(arg1.taskInfo.processStr, "#ffffff");
            this._taskProcess.updateData(this._cycleTxt, arg1.taskInfo);
            this.updateOptBtn(this._info);
            return;
        }

        /* internal  */updateOptBtn(arg1: CycleInfo): void
        {
            if (arg1.status == ETaskStatus._ETaskStatusCanGet && arg1.color >= 5) 
            {
                this._optBtn.label = Language.getString(20024);
            }
            else if (arg1.status != ETaskStatus._ETaskStatusNotCompleted) 
            {
                this._optBtn.label = Language.getString(20514);
            }
            else 
            {
                this._optBtn.label = Language.getString(20023);
            }
            return;
        }

        public guideRefresh(): void
        {
            this.hideGuide();
            var loc1=GuideTipsManager.getGuideTips(GuideTipsManager.Dir_BL, Language.getString(20515));
            loc1.x = this._optBtn.x + this._optBtn.width - 10;
            loc1.y = this._optBtn.y + this._optBtn.height / 2;
            addChild(loc1);
            this._lineBox = EffectManager.getLineBox(this._optBtn.width, this._optBtn.height, [16711680, 65280]);
            this._lineBox.x = this._optBtn.x;
            this._lineBox.y = this._optBtn.y;
            addChild(this._lineBox);
            return;
        }

        public hideGuide(): void
        {
            if (GuideTipsManager.guideTips.parent == this) 
            {
                GuideTipsManager.hideGuideTips();
            }
            EffectManager.disposeLineBox(this._lineBox);
            this._lineBox = null;
            return;
        }

        /* internal  */updateCountDown(arg1: int): void
        {
            this._freeTimer.text = Language.getString(20183) + "：" + RemainTimeTool.getRemainTimeBySeconds(arg1);
            if (arg1 > 0) 
            {
                if (!this._timer) 
                {
                    this._timer = new SecTimer(1, arg1);
                    this._timer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
                    this._timer.addListener(TimerType.COMPLETE, this.onTimerComHandler);
                }
                this._timer.repeatCount = arg1;
                if (!this._timer.running) 
                {
                    this._timer.start();
                }
            }
            else if (this._timer && this._timer.running) 
            {
                this._timer.stop();
                this._timer.isDelete = false;
            }
            return;
        }

        /* internal  */onTimerHandler(arg1: SecTimer): void
        {
            this._freeTimer.text = Language.getString(20183) + "：" + RemainTimeTool.getRemainTimeBySeconds(arg1.repeatCount);
            return;
        }

        /* internal  */onTimerComHandler(arg1: SecTimer): void
        {
            this._timer.stop();
            this._timer.isDelete = false;
            flash.utils.setTimeout(this.onTimerComImpl, 1500);
            return;
        }

        /* internal  */onTimerComImpl(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CycleTaskInfoReq));
            return;
        }

        /* internal  */onRefreshBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            EffectManager.glowFilterUnReg(this._optBtn);
            this._info.autoBuy = this._refreshPanel.autoBuySelected;
            this._info.flushCount = this._refreshPanel.flushCount;
            this._info.flushColor = this._refreshPanel.flushColor;
            return;
        }

        /* internal  */clearStar(): void
        {
            while (this._colorPanel.numChildren > 0) 
            {
                this._colorPanel.removeChildAt(0);
            }
            return;
        }

        /* internal  */onAutoBuySelectedChange(arg1: DataEvent): void
        {
            return;
        }

        public /* override */ updateData(arg1: Array<any>): void
        {
            this.dispose();
            var loc1=arg1[0];
            this._info = loc1;
            this.updateColor(loc1);
            this.updateStatus(loc1);
            this._refreshPanel.updateData();
            this._countValue.text = loc1.count + " / " + loc1.maxCount;
            if (loc1.status != ETaskStatus._ETaskStatusCanGet) 
            {
                EffectManager.glowFilterUnReg(this._optBtn);
            }
            else if (Cache.instance.role.entityInfo.level <= 40) 
            {
                EffectManager.glowFilterReg(this._optBtn);
            }
            return;
        }

        protected /* var */_info: CycleInfo;

        protected /* var */_line: Object /* flash.display.Bitmap */;

        protected /* var */_titleTxt: Object /* flash.text.TextField */;

        protected /* var */_colorPanel: GBox;

        protected /* var */_cycleTxt: Object /* flash.text.TextField */;

        protected /* var */_taskProcess: TaskProcessPanel;

        protected /* var */_optBtn: GButton;

        protected /* var */_refreshPanel: RefreshPanel;

        protected /* var */_moveAward: Object /* flash.text.TextField */;

        protected /* var */_rewardTxt: Object /* flash.text.TextField */;

        protected /* var */_rewardList: RewardList2;

        protected /* var */_countTxt: Object /* flash.text.TextField */;

        protected /* var */_countValue: Object /* flash.text.TextField */;

        /* internal */ /* var */_freeCount: Object /* flash.text.TextField */;

        /* internal */ /* var */_freeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_freeTimer: Object /* flash.text.TextField */;

        /* internal */ /* var */_timer: SecTimer;

        protected /* var */_lineBox: LineBox;

        /* internal */ /* var */_tf: Object /* flash.text.TextFormat */;
    }
